package com.lc202309;

import java.util.Stack;

/**
 * Description:
 *
 * @Create 2023/10/4 22:32
 * @Version 1.0
 */
public class MyQueue {
    private Stack<Integer> in;
    private Stack<Integer> out;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        this.in = new Stack<>();
        this.out = new Stack<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        in.push(x);
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        if (!out.empty()) {
            return out.pop();
        }
        while (!in.empty()) {
            out.push(in.pop());
        }
        return out.pop();
    }

    /**
     * Get the front element.
     */
    public int peek() {
        if (!out.empty()) {
            return out.peek();
        }
        while (!in.empty()) {
            out.push(in.pop());
        }
        return out.peek();
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return in.empty() && out.empty();
    }
}
